package com.briup.web.controller;

import com.briup.DTO.SaveOrUpdateAnimalDTO;
import com.briup.annotation.SystemLog;
import com.briup.exception.SystemException;
import com.briup.result.PageTemplate;
import com.briup.result.Result;
import com.briup.service.AnimalService;
import com.briup.service.QuarantineRegistrationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/animal")
@Api(tags = "动物模块")
public class AnimalController {
    @Autowired
    private AnimalService animalService;
    @GetMapping("/query")
    @ApiOperation("分页并根据条件查询动物基本信息以及对应批次和栏圈信息接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码"),
            @ApiImplicitParam(name = "pageSize",value = "每页大小"),
            @ApiImplicitParam(name = "aHealthy",value = "健康状态"),
            @ApiImplicitParam(name = "aGender",value = "性别")
    })
    public Result query(Integer pageNum,Integer pageSize,String aHealthy,String aGender) throws SystemException {
        PageTemplate pageTemplate=animalService.animalQuery(pageNum,pageSize,aHealthy,aGender);
        return Result.success(pageTemplate);
    }
    @GetMapping("/QRcode")
    @ApiOperation("根据动物ID生成对应的二维码信息接口")
    public Result generateQRCodeByAnimal(String animalId) throws SystemException {
        animalService.generateQRCodeByAnimal(animalId);
        return Result.success();
    }
    @GetMapping("/findByAnimalId")
    @ApiOperation("根据动物编号查询动物基本信息以及对应批次和栏舍栏圈信")
    public Result findByAnimalId(String animalId) throws SystemException {
        return Result.success(animalService.findByAnimalId(animalId));
    }
    @PostMapping("saveOrUpdate")
    @ApiOperation("新增或修改动物接口")
    public Result saveOrUpdate(@RequestBody SaveOrUpdateAnimalDTO saveOrUpdateAnimalDTO) throws SystemException {
        return Result.success(animalService.animalSaveOrUpdate(saveOrUpdateAnimalDTO));
    }
    @DeleteMapping("/deleteById")
    @ApiOperation("根据ID删除动物接口")
    @SystemLog(business = "根据ID删除动物接口")
    public Result deleteById(@PathVariable String id) throws SystemException {
        return animalService.deleteById(id);
    }
    @DeleteMapping("deleteByIdAll")
    @ApiOperation("批量删除动物接口")
    @SystemLog(business = "批量删除动物接口")
    public Result deleteByIdAll(@RequestBody List<String> ids) throws SystemException {
        return animalService.deleteByIdAll(ids);
    }
}
